import Mock from 'mockjs'
import {SUCCESS_CODE} from '../config/config'
import url from 'url'

let adminList = [
  {
    'id': 1,
    'phone': '18983188515',
    'status': 'ENABLE',
    'type': 'ADMIN',
    'name': '周舟',
    'password': '123456',
    'wxOpenId': '{}',
    'token': null,
    'roles': [{'roleName': 'ADMIN', 'permissions': []}]
  },
  {
    'id': 2,
    'phone': '18983188515',
    'status': 'ENABLE',
    'type': 'ADMIN',
    'name': '周舟',
    'password': '123456',
    'wxOpenId': '{}',
    'token': null,
    'roles': [{'roleName': 'ADMIN', 'permissions': []}]
  },
  {
    'id': 3,
    'phone': '18983188515',
    'status': 'ENABLE',
    'type': 'ADMIN',
    'name': '周舟',
    'password': '123456',
    'wxOpenId': '{}',
    'token': null,
    'roles': [{'roleName': 'ADMIN', 'permissions': []}]
  },
  {
    'id': 4,
    'phone': '18983188515',
    'status': 'ENABLE',
    'type': 'ADMIN',
    'name': '周舟',
    'password': '123456',
    'wxOpenId': '{}',
    'token': null,
    'roles': [{'roleName': 'ADMIN', 'permissions': []}]
  }
]

// 获取Admin用户列表
Mock.mock(/\/api\/sys\/users.+/, 'get', function (data) {
  let body = url.parse(data.url, true).query
  let result = JSON.parse(JSON.stringify(adminList))
  if (body.name) {
    result = result.filter(item => item.name.indexOf(body.name) !== -1)
  }
  if (body.loginName) {
    result = result.filter(item => item.loginName.indexOf(body.loginName) !== -1)
  }
  return {
    code: SUCCESS_CODE,
    msg: 'ok',
    adminList: result
  }
})
// 添加Admin
Mock.mock('/admin/add', 'post', function (data) {
  return {
    code: SUCCESS_CODE,
    msg: 'ok'
  }
})
